package cate.game.activity.optionalgift.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.activity.optionalgift.OptionalGiftActivity;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBOptionalGift;
import easy.java.dev.note.NoteField;

import java.util.Map;

@ClientMsg(title = "选择奖励的 请求")
@OperationSetter(value = GDOperation.OPTIONAL_GIFT, sub = "tid")
public class ChooseRewardReq implements MsgInput {
    @NoteField("功能id")
    public int funcId;
    @NoteField("礼包id")
    public int tid;
    @NoteField("key:格子号 value:奖励id")
    public Map<Integer, Integer> rewards;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        OptionalGiftActivity gift = cc.getRole().getActivity().getEnableActivitySingle(funcId);
        if (gift == null) {
            cc.getRole().getGame().notice.message(cc.getRole(), "活动未开启");
            return;
        }
        GameResult<OptionalGiftActivity> r = gift.chooseReward(tid, rewards);
        if (!r.ok()) {
            game.notice.message(cc.getRole(), r.message);
        }else {
            gift.noticeUpdate();
        }
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBOptionalGift.CHOOSE_GIFT_REQ;
    }
}
